{template 'common/header'}
<div class="panel we7-panel ng-scope" >
	<div class="panel-heading">修改时间看板</div>
	<div class="panel-body we7-padding">
			<div class="form-horizontal">
			<div class="form-group">
				<label class="col-sm-2 control-label">看板名称</label>
				<div class="col-sm-8">
					<input type="text" class="form-control" id="template_name" name="template_name" value="{$o['template_name']}">
				</div>
		 	</div>	
			<div class="form-group">
				<label class="col-sm-2 control-label">上班时间/下班时间(一日中)</label>
				<div class="col-sm-4">
					<input type="text" class="form-control" id="start" name="start" value="{$o['start']}">
				</div>
				<div class="col-sm-4">
					<input type="text" class="form-control" id="end" name="end" value="{$o['end']}">
				</div>				
		 	</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">中场休息时间(一日中)</label>
				<div class="col-sm-4">
					<input type="text" class="form-control" id="rest_start" name="rest_start" value="{$o['rest_start']}">
				</div>
				<div class="col-sm-4">
					<input type="text" class="form-control" id="rest_end" name="rest_end" value="{$o['rest_end']}">
				</div>				
		 	</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">时段配置</label>
				<div class="col-sm-8">
				    <div class="input-group">
				      <div class="input-group-addon">间隔</div>
		      		    <select class="form-control"  id="timeinterval" name="timeinterval">
					    	<option value="30" {if $o['timeinterval']=='30'}selected="selected"{else}{/if}>30</option>
					    	<option value="45" {if $o['timeinterval']=='45'}selected="selected"{else}{/if}>45</option>
					    	<option value="60" {if $o['timeinterval']=='60'}selected="selected"{else}{/if}>60</option>
					    	<option value="90" {if $o['timeinterval']=='90'}selected="selected"{else}{/if}>90</option>
					    	<option value="120" {if $o['timeinterval']=='120'}selected="selected"{else}{/if}>120</option>
					    	<option value="150" {if $o['timeinterval']=='150'}selected="selected"{else}{/if}>150</option>
					    	<option value="180" {if $o['timeinterval']=='180'}selected="selected"{else}{/if}>180</option>
					     </select>
				      <div class="input-group-addon">分</div>
				    </div>
				     <span class="help-block">&nbsp;&nbsp;技师的工作时间将按所选时段分拆被预约</span>			
				</div>							
		 	</div>	

			<div class="form-group">
				<label class="col-sm-2 control-label">假日(一周中)</label>
				<div class="col-sm-8">
					<div id="item-box">
					    <ul id="item-ul">
					    {if $week}	
					    {loop $week $k $v}
						<li class="input-group" id="item-list" lid="{php echo $k+1}" style="margin-top: 2px;">
						      <div class="input-group-addon">星期</div>
						      		    <select class="form-control"  id="restweek_value{php echo $k+1}" name="restweek_value1">
									    	<option value="0" {if $v=='0'}selected="selected"{else}{/if}>日</option>
									    	<option value="1" {if $v=='1'}selected="selected"{else}{/if}>一</option>
									    	<option value="2" {if $v=='2'}selected="selected"{else}{/if}>二</option>
									    	<option value="3" {if $v=='3'}selected="selected"{else}{/if}>三</option>
									    	<option value="4" {if $v=='4'}selected="selected"{else}{/if}>四</option>
									    	<option value="5" {if $v=='5'}selected="selected"{else}{/if}>五</option>
									    	<option value="6" {if $v=='6'}selected="selected"{else}{/if}>六</option>
									     </select>
						      <div class="input-group-addon" style="margin-left: 4px; background: #ff5d38; color: #fff;cursor:default;"" onclick="del_restweek({php echo $k+1})">删除</div>
					  	  </li>	
					  	  {/loop}
					  	  {else}
					  	  {/if}  	  
					    </ul>
					    <div id="add_restweek" class="addmenu">增加一个假日</div>		
					</div>    			    						
				</div>
		 	</div>	 		 		 		 		
			<br/>			 	
			<button type="button" id="save_" class="btn btn-info" style="display: block; margin-left: auto;margin-right: auto;">提交保存</button>
		</div>
	</div>
</div>
<style type="text/css">.right-content{padding: 0;}
.ishide{display: none;}
.addmenu{
    width: 150px;
    height:auto;
    background-color: #ff5d38;
    color: #FFFFFF;
    border-radius: 2px;
    border:0;
    display: block;
    padding: 2px 5px;
    box-sizing: border-box;
    box-shadow: 0 2px 2px 0 rgba(255,93,56, 0.14), 0 3px 1px -2px rgba(255,93,56, 0.2), 0 1px 5px 0 rgba(255,93,56, 0.12);    
    line-height: 35px;  
    outline: none;  
    margin-left: auto;
    margin-right: auto;
    margin-top: 10px;
    text-align: center;
    cursor:default;
}
.addmenu:hover{
    box-shadow: 0 14px 26px -12px rgba(255,93,56, 0.42), 0 4px 23px 0px rgba(0, 0, 0, 0.12), 0 8px 10px -5px rgba(255,93,56, 0.2);
}
</style>
<link rel="stylesheet" href="{MODULE_URL}public/css/Toast.css">
<script src="{MODULE_URL}public/js/Toast.js"></script> 
<script type="text/javascript">
	$('#add_restweek').on('click',function(){
		var _len = $("#item-ul li").length+1;
		if(_len > 7){
			mqToast({type:1,context: '抱歉，你添加的假日已超出一周天数'}); 
			return false;
		}
		$("#item-ul").append( 
			'<li class="input-group" id="item-list" lid="'+_len+'" style="margin-top: 2px;">'+
		      '<div class="input-group-addon">星期</div>'+
		      		    '<select class="form-control"  id="restweek_value'+_len+'" name="estweek_value'+_len+'">'+
					    	'<option value="0">日</option>'+
					    	'<option value="1">一</option>'+
					    	'<option value="2">二</option>'+
					    	'<option value="3">三</option>'+
					    	'<option value="4">四</option>'+
					    	'<option value="5">五</option>'+
					    	'<option value="6">六</option>'+
					     '</select>'+
		      '<div class="input-group-addon" style="margin-left: 4px; background: #ff5d38; color: #fff;cursor:default;"" onclick="del_restweek('+_len+')">删除</div>'+
	  	  '</li>'
		);
		return false;
	})	

	var del_restweek = function(index){
		var _len = $("#item-ul li").length+1;
	    $("#item-list[lid='"+index+"']").remove();
		for(var i=index+1,j=_len;i<j;i++)
		{
			var restweek_value = $.trim($('#restweek_value'+i+' option:selected').val());
			var restweek_name = $.trim($('#restweek_value'+i+' option:selected').text());
			$("#mcard-level-list[lid=\'"+i+"\']").replaceWith(
				'<li class="input-group" id="item-list" lid="'+_len+'" style="margin-top: 2px;">'+
			      '<div class="input-group-addon">星期</div>'+
			      		    '<select class="form-control"  id="restweek_value'+_len+'" name="estweek_value'+_len+'">'+
			      		    	'<option value="'+restweek_value+'" selected="selected">'+restweek_name+'</option>'+
						    	'<option value="0">日</option>'+
						    	'<option value="1">一</option>'+
						    	'<option value="2">二</option>'+
						    	'<option value="3">三</option>'+
						    	'<option value="4">四</option>'+
						    	'<option value="5">五</option>'+
						    	'<option value="6">六</option>'+
						     '</select>'+
			      '<div class="input-group-addon" style="margin-left: 4px; background: #ff5d38; color: #fff;cursor:default;"" onclick="del_restweek('+_len+')">删除</div>'+
			  	'</li>'				
			)	
		}    
	}

	$('#save_').on('click',function(){
		var template_name = $.trim($('#template_name').val());
		var start = $.trim($('#start').val());
		var end  =$.trim($('#end').val());
		var rest_start = $.trim($('#rest_start').val());
		var rest_end = $.trim($('#rest_end').val());
		var rest_week = restWeek();
		var timeinterval = $.trim($('#timeinterval').val());
		if(template_name==''){
			mqToast({type:1,context:'请输入看板名称'});
			return '';
		}
		if(start==''){
			mqToast({type:1,context:'请输入上班时间'});
			return false;
		}
		if(end==''){
			mqToast({type:1,context:'请输入下班时间'});
			return false;
		}
		$.ajax({
			url:"{php echo $this->createWebUrl('save_timetemplateedit',array('tid'=>$o['tid']));}&version_id="+"{$_GPC['version_id']}",
			data:{template_name:template_name,start:start,end:end,rest_start:rest_start,rest_end:rest_end,timeinterval:timeinterval,rest_week:rest_week},
			dataType:"json",
			type:"post",
			success:function(res){
				if(res.status=='1'){
					mqToast({type:1,context:res.msg});
					return false;					
				}else{
					mqToast({type:1,context:res.msg});
					return false;					
				}				
			}
		});

	})

	var restWeek = function(){
		var _len = $("#item-ul li").length;
		var weekarr = [];
		if(_len>0){
			for (var i = 0; i < _len; i++) {
				var j= i+1;
				var val_ = $.trim($('#restweek_value'+j+' option:selected').val());
				weekarr[i] = val_
			}
			return weekarr.join('oOo');
		}else{
			return '';
		}		
	}
</script>
{template 'common/footer'}